import paho.mqtt.client as mqtt

# MQTT Broker 的地址和端口
broker_address = "localhost"  # 替换为实际的 Broker 地址
broker_port = 1883  # 默认端口

# 创建 MQTT 客户端实例
client = mqtt.Client(client_id="PythonPublisher")

# 连接到 MQTT Broker
client.connect(broker_address, broker_port)

# 发布消息到指定的主题
topic = "test/topic"
message = "Hello, MQTT!"
client.publish(topic, message)

# 断开连接
client.disconnect()
